package com.hcw.blog.base.enumdata;

import com.alibaba.druid.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springframework.util.Assert;

@Getter
@AllArgsConstructor
public enum UserTypeEnum {

    SUP_ADMIN("general_user", "超级管理员"),
    ADMIN("admin", "管理员"),
    GENERAL_USER("general_user", "普通用户")
    ;

    private final String code;
    private final String desc;

    public static boolean checkCode(String code) {
        if (StringUtils.isEmpty(code)) {
            return false;
        }
        for (UserTypeEnum userTypeEnum : values()) {
            if (userTypeEnum.getCode().equals(code)) {
                return true;
            }
        }
        return false;
    }

    public static UserTypeEnum getByCode(String code) {
        for (UserTypeEnum userTypeEnum : values()) {
            if (userTypeEnum.getCode().equals(code)) {
                return userTypeEnum;
            }
        }
        Assert.isTrue(true,"code不存在" + code);
        return null;
    }

}
